home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / docs / gdb / gdb.i4 (.txt) < prev    next >
GNU Info File  |  1994-07-26  |  51KB  |  983 lines

  1. This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input
  2. file gdb.texinfo.
  3. START-INFO-DIR-ENTRY
  4. * Gdb::                         The GNU debugger.
  5. END-INFO-DIR-ENTRY
  6.    This file documents the GNU debugger GDB.
  7.    This is Edition 4.12, January 1994, of `Debugging with GDB: the GNU
  8. Source-Level Debugger' for GDB Version 4.12.
  9.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  10. Foundation, Inc.
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided also
  16. that the entire resulting derived work is distributed under the terms
  17. of a permission notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions.
  21. File: gdb.info,  Node: Print Settings,  Next: Value History,  Prev: Auto Display,  Up: Data
  22. Print settings
  23. ==============
  24.    GDB provides the following ways to control how arrays, structures,
  25. and symbols are printed.
  26. These settings are useful for debugging programs in any language:
  27. `set print address'
  28. `set print address on'
  29.      GDB prints memory addresses showing the location of stack traces,
  30.      structure values, pointer values, breakpoints, and so forth, even
  31.      when it also displays the contents of those addresses.  The default
  32.      is `on'.  For example, this is what a stack frame display looks
  33.      like, with `set print address on':
  34.           (gdb) f
  35.           #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
  36.               at input.c:530
  37.           530         if (lquote != def_lquote)
  38. `set print address off'
  39.      Do not print addresses when displaying their contents.  For
  40.      example, this is the same stack frame displayed with `set print
  41.      address off':
  42.           (gdb) set print addr off
  43.           (gdb) f
  44.           #0  set_quotes (lq="<<", rq=">>") at input.c:530
  45.           530         if (lquote != def_lquote)
  46.      You can use `set print address off' to eliminate all machine
  47.      dependent displays from the GDB interface.  For example, with
  48.      `print address off', you should get the same text for backtraces on
  49.      all machines--whether or not they involve pointer arguments.
  50. `show print address'
  51.      Show whether or not addresses are to be printed.
  52.    When GDB prints a symbolic address, it normally prints the closest
  53. earlier symbol plus an offset.  If that symbol does not uniquely
  54. identify the address (for example, it is a name whose scope is a single
  55. source file), you may need to disambiguate.  One way to do this is with
  56. `info line', for example `info line *0x4537'.  Alternately, you can set
  57. GDB to print the source file and line number when it prints a symbolic
  58. address:
  59. `set print symbol-filename on'
  60.      Tell GDB to print the source file name and line number of a symbol
  61.      in the symbolic form of an address.
  62. `set print symbol-filename off'
  63.      Do not print source file name and line number of a symbol.  This
  64.      is the default.
  65. `show print symbol-filename'
  66.      Show whether or not GDB will print the source file name and line
  67.      number of a symbol in the symbolic form of an address.
  68.    Another situation where it is helpful to show symbol filenames and
  69. line numbers is when disassembling code; GDB shows you the line number
  70. and source file that corresponds to each instruction.
  71.    Also, you may wish to see the symbolic form only if the address being
  72. printed is reasonably close to the closest earlier symbol:
  73. `set print max-symbolic-offset MAX-OFFSET'
  74.      Tell GDB to only display the symbolic form of an address if the
  75.      offset between the closest earlier symbol and the address is less
  76.      than MAX-OFFSET.  The default is 0, which means to always print the
  77.      symbolic form of an address, if any symbol precedes it.
  78. `show print max-symbolic-offset'
  79.      Ask how large the maximum offset is that GDB prints in a symbolic
  80.      address.
  81.    Sometimes GDB can tell you more about an address if it does an
  82. extensive search of its symbol information.  The default is to provide
  83. a quick symbolic display that is usually correct, but which may not give
  84. the most useful answer when working in some object file formats.  If
  85. you are not getting the information you need, try:
  86. `set print fast-symbolic-addr off'
  87.      Search all symbol information when displaying an address
  88.      symbolically.  This setting may display more information about
  89.      static variables, for example, but also takes longer.
  90. `set print fast-symbolic-addr'
  91. `set print fast-symbolic-addr on'
  92.      Search only the "minimal symbol information" when displaying
  93.      symbolic information about an address.  This is the default.
  94. `show print fast-symbolic-addr'
  95.      Ask whether GDB is using a fast or slow method of printing
  96.      symbolic address.
  97.    If you have a pointer and you are not sure where it points, try `set
  98. print symbol-filename on' and `set print fast-symbolic-addr off'.  Then
  99. you can determine the name and source file location of the variable
  100. where it points, using `p/a POINTER'.  This interprets the address in
  101. symbolic form.  For example, here GDB shows that a variable `ptt'
  102. points at another variable `t', defined in `hi2.c':
  103.      (gdb) set print fast-symbolic-addr off
  104.      (gdb) set print symbol-filename on
  105.      (gdb) p/a ptt
  106.      $4 = 0xe008 <t in hi2.c>
  107.      *Warning:* For pointers that point to a local variable, `p/a' does
  108.      not show the symbol name and filename of the referent, even with
  109.      the appropriate `set print' options turned on.
  110.    Other settings control how different kinds of objects are printed:
  111. `set print array'
  112. `set print array on'
  113.      Pretty-print arrays.  This format is more convenient to read, but
  114.      uses more space.  The default is off.
  115. `set print array off'
  116.      Return to compressed format for arrays.
  117. `show print array'
  118.      Show whether compressed or pretty format is selected for displaying
  119.      arrays.
  120. `set print elements NUMBER-OF-ELEMENTS'
  121.      If GDB is printing a large array, it stops printing after it has
  122.      printed the number of elements set by the `set print elements'
  123.      command.  This limit also applies to the display of strings.
  124.      Setting the number of elements to zero means that the printing is
  125.      unlimited.
  126. `show print elements'
  127.      Display the number of elements of a large array that GDB prints
  128.      before losing patience.
  129. `set print pretty on'
  130.      Cause GDB to print structures in an indented format with one
  131.      member per line, like this:
  132.           $1 = {
  133.             next = 0x0,
  134.             flags = {
  135.               sweet = 1,
  136.               sour = 1
  137.             },
  138.             meat = 0x54 "Pork"
  139.           }
  140. `set print pretty off'
  141.      Cause GDB to print structures in a compact format, like this:
  142.           $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
  143.           meat = 0x54 "Pork"}
  144.      This is the default format.
  145. `show print pretty'
  146.      Show which format GDB is using to print structures.
  147. `set print sevenbit-strings on'
  148.      Print using only seven-bit characters; if this option is set, GDB
  149.      displays any eight-bit characters (in strings or character values)
  150.      using the notation `\'NNN.  This setting is best if you are
  151.      working in English (ASCII) and you use the high-order bit of
  152.      characters as a marker or "meta" bit.
  153. `set print sevenbit-strings off'
  154.      Print full eight-bit characters.  This allows the use of more
  155.      international character sets, and is the default.
  156. `show print sevenbit-strings'
  157.      Show whether or not GDB is printing only seven-bit characters.
  158. `set print union on'
  159.      Tell GDB to print unions which are contained in structures.  This
  160.      is the default setting.
  161. `set print union off'
  162.      Tell GDB not to print unions which are contained in structures.
  163. `show print union'
  164.      Ask GDB whether or not it will print unions which are contained in
  165.      structures.
  166.      For example, given the declarations
  167.           typedef enum {Tree, Bug} Species;
  168.           typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
  169.           typedef enum {Caterpillar, Cocoon, Butterfly}
  170.                         Bug_forms;
  171.           
  172.           struct thing {
  173.             Species it;
  174.             union {
  175.               Tree_forms tree;
  176.               Bug_forms bug;
  177.             } form;
  178.           };
  179.           
  180.           struct thing foo = {Tree, {Acorn}};
  181.      with `set print union on' in effect `p foo' would print
  182.           $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
  183.      and with `set print union off' in effect it would print
  184.           $1 = {it = Tree, form = {...}}
  185. These settings are of interest when debugging C++ programs:
  186. `set print demangle'
  187. `set print demangle on'
  188.      Print C++ names in their source form rather than in the encoded
  189.      ("mangled") form passed to the assembler and linker for type-safe
  190.      linkage.  The default is `on'.
  191. `show print demangle'
  192.      Show whether C++ names are printed in mangled or demangled form.
  193. `set print asm-demangle'
  194. `set print asm-demangle on'
  195.      Print C++ names in their source form rather than their mangled
  196.      form, even in assembler code printouts such as instruction
  197.      disassemblies.  The default is off.
  198. `show print asm-demangle'
  199.      Show whether C++ names in assembly listings are printed in mangled
  200.      or demangled form.
  201. `set demangle-style STYLE'
  202.      Choose among several encoding schemes used by different compilers
  203.      to represent C++ names.  The choices for STYLE are currently:
  204.     `auto'
  205.           Allow GDB to choose a decoding style by inspecting your
  206.           program.
  207.     `gnu'
  208.           Decode based on the GNU C++ compiler (`g++') encoding
  209.           algorithm.
  210.     `lucid'
  211.           Decode based on the Lucid C++ compiler (`lcc') encoding
  212.           algorithm.
  213.     `arm'
  214.           Decode using the algorithm in the `C++ Annotated Reference
  215.           Manual'.  *Warning:* this setting alone is not sufficient to
  216.           allow debugging `cfront'-generated executables.  GDB would
  217.           require further enhancement to permit that.
  218. `show demangle-style'
  219.      Display the encoding style currently in use for decoding C++
  220.      symbols.
  221. `set print object'
  222. `set print object on'
  223.      When displaying a pointer to an object, identify the *actual*
  224.      (derived) type of the object rather than the *declared* type, using
  225.      the virtual function table.
  226. `set print object off'
  227.      Display only the declared type of objects, without reference to the
  228.      virtual function table.  This is the default setting.
  229. `show print object'
  230.      Show whether actual, or declared, object types are displayed.
  231. `set print vtbl'
  232. `set print vtbl on'
  233.      Pretty print C++ virtual function tables.  The default is off.
  234. `set print vtbl off'
  235.      Do not pretty print C++ virtual function tables.
  236. `show print vtbl'
  237.      Show whether C++ virtual function tables are pretty printed, or
  238.      not.
  239. File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Print Settings,  Up: Data
  240. Value history
  241. =============
  242.    Values printed by the `print' command are saved in the GDB "value
  243. history" so that you can refer to them in other expressions.  Values are
  244. kept until the symbol table is re-read or discarded (for example with
  245. the `file' or `symbol-file' commands).  When the symbol table changes,
  246. the value history is discarded, since the values may contain pointers
  247. back to the types defined in the symbol table.
  248.    The values printed are given "history numbers" by which you can
  249. refer to them.  These are successive integers starting with one.
  250. `print' shows you the history number assigned to a value by printing
  251. `$NUM = ' before the value; here NUM is the history number.
  252.    To refer to any previous value, use `$' followed by the value's
  253. history number.  The way `print' labels its output is designed to
  254. remind you of this.  Just `$' refers to the most recent value in the
  255. history, and `$$' refers to the value before that.  `$$N' refers to the
  256. Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
  257. equivalent to `$$', and `$$0' is equivalent to `$'.
  258.    For example, suppose you have just printed a pointer to a structure
  259. and want to see the contents of the structure.  It suffices to type
  260.      p *$
  261.    If you have a chain of structures where the component `next' points
  262. to the next one, you can print the contents of the next one with this:
  263.      p *$.next
  264. You can print successive links in the chain by repeating this
  265. command--which you can do by just typing RET.
  266.    Note that the history records values, not expressions.  If the value
  267. of `x' is 4 and you type these commands:
  268.      print x
  269.      set x=5
  270. then the value recorded in the value history by the `print' command
  271. remains 4 even though the value of `x' has changed.
  272. `show values'
  273.      Print the last ten values in the value history, with their item
  274.      numbers.  This is like `p $$9' repeated ten times, except that
  275.      `show values' does not change the history.
  276. `show values N'
  277.      Print ten history values centered on history item number N.
  278. `show values +'
  279.      Print ten history values just after the values last printed.  If
  280.      no more values are available, produces no display.
  281.    Pressing RET to repeat `show values N' has exactly the same effect
  282. as `show values +'.
  283. File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
  284. Convenience variables
  285. =====================
  286.    GDB provides "convenience variables" that you can use within GDB to
  287. hold on to a value and refer to it later.  These variables exist
  288. entirely within GDB; they are not part of your program, and setting a
  289. convenience variable has no direct effect on further execution of your
  290. program.  That is why you can use them freely.
  291.    Convenience variables are prefixed with `$'.  Any name preceded by
  292. `$' can be used for a convenience variable, unless it is one of the
  293. predefined machine-specific register names (*note Registers::.).
  294. (Value history references, in contrast, are *numbers* preceded by `$'.
  295. *Note Value history: Value History.)
  296.    You can save a value in a convenience variable with an assignment
  297. expression, just as you would set a variable in your program.  For
  298. example:
  299.      set $foo = *object_ptr
  300. would save in `$foo' the value contained in the object pointed to by
  301. `object_ptr'.
  302.    Using a convenience variable for the first time creates it, but its
  303. value is `void' until you assign a new value.  You can alter the value
  304. with another assignment at any time.
  305.    Convenience variables have no fixed types.  You can assign a
  306. convenience variable any type of value, including structures and
  307. arrays, even if that variable already has a value of a different type.
  308. The convenience variable, when used as an expression, has the type of
  309. its current value.
  310. `show convenience'
  311.      Print a list of convenience variables used so far, and their
  312.      values.  Abbreviated `show con'.
  313.    One of the ways to use a convenience variable is as a counter to be
  314. incremented or a pointer to be advanced.  For example, to print a field
  315. from successive elements of an array of structures:
  316.      set $i = 0
  317.      print bar[$i++]->contents
  318.      ... repeat that command by typing RET.
  319.    Some convenience variables are created automatically by GDB and given
  320. values likely to be useful.
  321.      The variable `$_' is automatically set by the `x' command to the
  322.      last address examined (*note Examining memory: Memory.).  Other
  323.      commands which provide a default address for `x' to examine also
  324.      set `$_' to that address; these commands include `info line' and
  325.      `info breakpoint'.  The type of `$_' is `void *' except when set
  326.      by the `x' command, in which case it is a pointer to the type of
  327.      `$__'.
  328. `$__'
  329.      The variable `$__' is automatically set by the `x' command to the
  330.      value found in the last address examined.  Its type is chosen to
  331.      match the format in which the data was printed.
  332. File: gdb.info,  Node: Registers,  Next: Floating Point Hardware,  Prev: Convenience Vars,  Up: Data
  333. Registers
  334. =========
  335.    You can refer to machine register contents, in expressions, as
  336. variables with names starting with `$'.  The names of registers are
  337. different for each machine; use `info registers' to see the names used
  338. on your machine.
  339. `info registers'
  340.      Print the names and values of all registers except floating-point
  341.      registers (in the selected stack frame).
  342. `info all-registers'
  343.      Print the names and values of all registers, including
  344.      floating-point registers.
  345. `info registers REGNAME ...'
  346.      Print the relativized value of each specified register REGNAME.
  347.      rEGNAME may be any register name valid on the machine you are
  348.      using, with or without the initial `$'.
  349.    GDB has four "standard" register names that are available (in
  350. expressions) on most machines--whenever they do not conflict with an
  351. architecture's canonical mnemonics for registers.  The register names
  352. `$pc' and `$sp' are used for the program counter register and the stack
  353. pointer.  `$fp' is used for a register that contains a pointer to the
  354. current stack frame, and `$ps' is used for a register that contains the
  355. processor status.  For example, you could print the program counter in
  356. hex with
  357.      p/x $pc
  358. or print the instruction to be executed next with
  359.      x/i $pc
  360. or add four to the stack pointer(1) with
  361.      set $sp += 4
  362.    Whenever possible, these four standard register names are available
  363. on your machine even though the machine has different canonical
  364. mnemonics, so long as there is no conflict.  The `info registers'
  365. command shows the canonical names.  For example, on the SPARC, `info
  366. registers' displays the processor status register as `$psr' but you can
  367. also refer to it as `$ps'.
  368.    GDB always considers the contents of an ordinary register as an
  369. integer when the register is examined in this way.  Some machines have
  370. special registers which can hold nothing but floating point; these
  371. registers are considered to have floating point values.  There is no way
  372. to refer to the contents of an ordinary register as floating point value
  373. (although you can *print* it as a floating point value with `print/f
  374. $REGNAME').
  375.    Some registers have distinct "raw" and "virtual" data formats.  This
  376. means that the data format in which the register contents are saved by
  377. the operating system is not the same one that your program normally
  378. sees.  For example, the registers of the 68881 floating point
  379. coprocessor are always saved in "extended" (raw) format, but all C
  380. programs expect to work with "double" (virtual) format.  In such cases,
  381. GDB normally works with the virtual format only (the format that makes
  382. sense for your program), but the `info registers' command prints the
  383. data in both formats.
  384.    Normally, register values are relative to the selected stack frame
  385. (*note Selecting a frame: Selection.).  This means that you get the
  386. value that the register would contain if all stack frames farther in
  387. were exited and their saved registers restored.  In order to see the
  388. true contents of hardware registers, you must select the innermost
  389. frame (with `frame 0').
  390.    However, GDB must deduce where registers are saved, from the machine
  391. code generated by your compiler.  If some registers are not saved, or if
  392. GDB is unable to locate the saved registers, the selected stack frame
  393. makes no difference.
  394. `set rstack_high_address ADDRESS'
  395.      On AMD 29000 family processors, registers are saved in a separate
  396.      "register stack".  There is no way for GDB to determine the extent
  397.      of this stack.  Normally, GDB just assumes that the stack is "large
  398.      enough".  This may result in GDB referencing memory locations that
  399.      do not exist.  If necessary, you can get around this problem by
  400.      specifying the ending address of the register stack with the `set
  401.      rstack_high_address' command.  The argument should be an address,
  402.      which you probably want to precede with `0x' to specify in
  403.      hexadecimal.
  404. `show rstack_high_address'
  405.      Display the current limit of the register stack, on AMD 29000
  406.      family processors.
  407.    ---------- Footnotes ----------
  408.    (1)  This is a way of removing one word from the stack, on machines
  409. where stacks grow downward in memory (most machines, nowadays).  This
  410. assumes that the innermost stack frame is selected; setting `$sp' is
  411. not allowed when other stack frames are selected.  To pop entire frames
  412. off the stack, regardless of machine architecture, use `return'; *note
  413. Returning from a function: Returning..
  414. File: gdb.info,  Node: Floating Point Hardware,  Prev: Registers,  Up: Data
  415. Floating point hardware
  416. =======================
  417.    Depending on the host machine architecture, GDB may be able to give
  418. you more information about the status of the floating point hardware.
  419. `info float'
  420.      Display hardware-dependent information about the floating point
  421.      unit.  The exact contents and layout vary depending on the
  422.      floating point chip; on some platforms, `info float' is not
  423.      available at all.
  424. File: gdb.info,  Node: Languages,  Next: Symbols,  Prev: Data,  Up: Top
  425. Using GDB with Different Languages
  426. **********************************
  427.    Although programming languages generally have common aspects, they
  428. are rarely expressed in the same manner.  For instance, in ANSI C,
  429. dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
  430. it is accomplished by `p^'.  Values can also be represented (and
  431. displayed) differently.  Hex numbers in C are written like `0x1ae',
  432. while in Modula-2 they appear as `1AEH'.
  433.    Language-specific information is built into GDB for some languages,
  434. allowing you to express operations like the above in your program's
  435. native language, and allowing GDB to output values in a manner
  436. consistent with the syntax of your program's native language.  The
  437. language you use to build expressions, called the "working language",
  438. can be selected manually, or GDB can set it automatically.
  439. * Menu:
  440. * Setting::                     Switching between source languages
  441. * Show::                        Displaying the language
  442. * Checks::                      Type and range checks
  443. * Support::                     Supported languages
  444. File: gdb.info,  Node: Setting,  Next: Show,  Up: Languages
  445. Switching between source languages
  446. ==================================
  447.    There are two ways to control the working language--either have GDB
  448. set it automatically, or select it manually yourself.  You can use the
  449. `set language' command for either purpose.  On startup, GDB defaults to
  450. setting the language automatically.
  451. * Menu:
  452. * Manually::                    Setting the working language manually
  453. * Automatically::               Having GDB infer the source language
  454. File: gdb.info,  Node: Manually,  Next: Automatically,  Up: Setting
  455. Setting the working language
  456. ----------------------------
  457.    If you allow GDB to set the language automatically, expressions are
  458. interpreted the same way in your debugging session and your program.
  459.    If you wish, you may set the language manually.  To do this, issue
  460. the command `set language LANG', where LANG is the name of a language,
  461. such as `c' or `modula-2'.  For a list of the supported languages, type
  462. `set language'.
  463.    Setting the language manually prevents GDB from updating the working
  464. language automatically.  This can lead to confusion if you try to debug
  465. a program when the working language is not the same as the source
  466. language, when an expression is acceptable to both languages--but means
  467. different things.  For instance, if the current source file were
  468. written in C, and GDB was parsing Modula-2, a command such as:
  469.      print a = b + c
  470. might not have the effect you intended.  In C, this means to add `b'
  471. and `c' and place the result in `a'.  The result printed would be the
  472. value of `a'.  In Modula-2, this means to compare `a' to the result of
  473. `b+c', yielding a `BOOLEAN' value.
  474. File: gdb.info,  Node: Automatically,  Prev: Manually,  Up: Setting
  475. Having GDB infer the source language
  476. ------------------------------------
  477.    To have GDB set the working language automatically, use `set
  478. language local' or `set language auto'.  GDB then infers the language
  479. that a program was written in by looking at the name of its source
  480. files, and examining their extensions:
  481. `*.mod'
  482.      Modula-2 source file
  483. `*.c'
  484.      C source file
  485. `*.C'
  486. `*.cc'
  487.      C++ source file
  488.    This information is recorded for each function or procedure in a
  489. source file.  When your program stops in a frame (usually by
  490. encountering a breakpoint), GDB sets the working language to the
  491. language recorded for the function in that frame.  If the language for
  492. a frame is unknown (that is, if the function or block corresponding to
  493. the frame was defined in a source file that does not have a recognized
  494. extension), the current working language is not changed, and GDB issues
  495. a warning.
  496.    This may not seem necessary for most programs, which are written
  497. entirely in one source language.  However, program modules and libraries
  498. written in one source language can be used by a main program written in
  499. a different source language.  Using `set language auto' in this case
  500. frees you from having to set the working language manually.
  501. File: gdb.info,  Node: Show,  Next: Checks,  Prev: Setting,  Up: Languages
  502. Displaying the language
  503. =======================
  504.    The following commands help you find out which language is the
  505. working language, and also what language source files were written in.
  506. `show language'
  507.      Display the current working language.  This is the language you
  508.      can use with commands such as `print' to build and compute
  509.      expressions that may involve variables in your program.
  510. `info frame'
  511.      Among the other information listed here (*note Information about a
  512.      frame: Frame Info.) is the source language for this frame.  This
  513.      language becomes the working language if you use an identifier
  514.      from this frame.
  515. `info source'
  516.      Among the other information listed here (*note Examining the
  517.      Symbol Table: Symbols.) is the source language of this source file.
  518. File: gdb.info,  Node: Checks,  Next: Support,  Prev: Show,  Up: Languages
  519. Type and range checking
  520. =======================
  521.      *Warning:* In this release, the GDB commands for type and range
  522.      checking are included, but they do not yet have any effect.  This
  523.      section documents the intended facilities.
  524.    Some languages are designed to guard you against making seemingly
  525. common errors through a series of compile- and run-time checks.  These
  526. include checking the type of arguments to functions and operators, and
  527. making sure mathematical overflows are caught at run time.  Checks such
  528. as these help to ensure a program's correctness once it has been
  529. compiled by eliminating type mismatches, and providing active checks
  530. for range errors when your program is running.
  531.    GDB can check for conditions like the above if you wish.  Although
  532. GDB does not check the statements in your program, it can check
  533. expressions entered directly into GDB for evaluation via the `print'
  534. command, for example.  As with the working language, GDB can also
  535. decide whether or not to check automatically based on your program's
  536. source language.  *Note Supported languages: Support, for the default
  537. settings of supported languages.
  538. * Menu:
  539. * Type Checking::               An overview of type checking
  540. * Range Checking::              An overview of range checking
  541. File: gdb.info,  Node: Type Checking,  Next: Range Checking,  Up: Checks
  542. An overview of type checking
  543. ----------------------------
  544.    Some languages, such as Modula-2, are strongly typed, meaning that
  545. the arguments to operators and functions have to be of the correct type,
  546. otherwise an error occurs.  These checks prevent type mismatch errors
  547. from ever causing any run-time problems.  For example,
  548.      1 + 2 => 3
  549.      error--> 1 + 2.3
  550.    The second example fails because the `CARDINAL' 1 is not
  551. type-compatible with the `REAL' 2.3.
  552.    For expressions you use in GDB commands, you can tell the GDB type
  553. checker to skip checking; to treat any mismatches as errors and abandon
  554. the expression; or only issue warnings when type mismatches occur, but
  555. evaluate the expression anyway.  When you choose the last of these, GDB
  556. evaluates expressions like the second example above, but also issues a
  557. warning.
  558.    Even though you may turn type checking off, other type-based reasons
  559. may prevent GDB from evaluating an expression.  For instance, GDB does
  560. not know how to add an `int' and a `struct foo'.  These particular type
  561. errors have nothing to do with the language in use, and usually arise
  562. from expressions, such as the one described above, which make little
  563. sense to evaluate anyway.
  564.    Each language defines to what degree it is strict about type.  For
  565. instance, both Modula-2 and C require the arguments to arithmetical
  566. operators to be numbers.  In C, enumerated types and pointers can be
  567. represented as numbers, so that they are valid arguments to mathematical
  568. operators.  *Note Supported languages: Support, for further details on
  569. specific languages.
  570.    GDB provides some additional commands for controlling the type
  571. checker:
  572. `set check type auto'
  573.      Set type checking on or off based on the current working language.
  574.      *Note Supported languages: Support, for the default settings for
  575.      each language.
  576. `set check type on'
  577. `set check type off'
  578.      Set type checking on or off, overriding the default setting for the
  579.      current working language.  Issue a warning if the setting does not
  580.      match the language default.  If any type mismatches occur in
  581.      evaluating an expression while typechecking is on, GDB prints a
  582.      message and aborts evaluation of the expression.
  583. `set check type warn'
  584.      Cause the type checker to issue warnings, but to always attempt to
  585.      evaluate the expression.  Evaluating the expression may still be
  586.      impossible for other reasons.  For example, GDB cannot add numbers
  587.      and structures.
  588. `show type'
  589.      Show the current setting of the type checker, and whether or not
  590.      GDB is setting it automatically.
  591. File: gdb.info,  Node: Range Checking,  Prev: Type Checking,  Up: Checks
  592. An overview of range checking
  593. -----------------------------
  594.    In some languages (such as Modula-2), it is an error to exceed the
  595. bounds of a type; this is enforced with run-time checks.  Such range
  596. checking is meant to ensure program correctness by making sure
  597. computations do not overflow, or indices on an array element access do
  598. not exceed the bounds of the array.
  599.    For expressions you use in GDB commands, you can tell GDB to treat
  600. range errors in one of three ways: ignore them, always treat them as
  601. errors and abandon the expression, or issue warnings but evaluate the
  602. expression anyway.
  603.    A range error can result from numerical overflow, from exceeding an
  604. array index bound, or when you type a constant that is not a member of
  605. any type.  Some languages, however, do not treat overflows as an error.
  606. In many implementations of C, mathematical overflow causes the result
  607. to "wrap around" to lower values--for example, if M is the largest
  608. integer value, and S is the smallest, then
  609.      M + 1 => S
  610.    This, too, is specific to individual languages, and in some cases
  611. specific to individual compilers or machines.  *Note Supported
  612. languages: Support, for further details on specific languages.
  613.    GDB provides some additional commands for controlling the range
  614. checker:
  615. `set check range auto'
  616.      Set range checking on or off based on the current working language.
  617.      *Note Supported languages: Support, for the default settings for
  618.      each language.
  619. `set check range on'
  620. `set check range off'
  621.      Set range checking on or off, overriding the default setting for
  622.      the current working language.  A warning is issued if the setting
  623.      does not match the language default.  If a range error occurs,
  624.      then a message is printed and evaluation of the expression is
  625.      aborted.
  626. `set check range warn'
  627.      Output messages when the GDB range checker detects a range error,
  628.      but attempt to evaluate the expression anyway.  Evaluating the
  629.      expression may still be impossible for other reasons, such as
  630.      accessing memory that the process does not own (a typical example
  631.      from many Unix systems).
  632. `show range'
  633.      Show the current setting of the range checker, and whether or not
  634.      it is being set automatically by GDB.
  635. File: gdb.info,  Node: Support,  Prev: Checks,  Up: Languages
  636. Supported languages
  637. ===================
  638.    GDB 4 supports C, C++, and Modula-2.  Some GDB features may be used
  639. in expressions regardless of the language you use: the GDB `@' and `::'
  640. operators, and the `{type}addr' construct (*note Expressions:
  641. Expressions.) can be used with the constructs of any supported language.
  642.    The following sections detail to what degree each source language is
  643. supported by GDB.  These sections are not meant to be language
  644. tutorials or references, but serve only as a reference guide to what the
  645. GDB expression parser accepts, and what input and output formats should
  646. look like for different languages.  There are many good books written
  647. on each of these languages; please look to these for a language
  648. reference or tutorial.
  649. * Menu:
  650. * C::                           C and C++
  651. * Modula-2::                    Modula-2
  652. File: gdb.info,  Node: C,  Next: Modula-2,  Up: Support
  653. C and C++
  654. ---------
  655.    Since C and C++ are so closely related, many features of GDB apply
  656. to both languages.  Whenever this is the case, we discuss both languages
  657. together.
  658.    The C++ debugging facilities are jointly implemented by the GNU C++
  659. compiler and GDB.  Therefore, to debug your C++ code effectively, you
  660. must compile your C++ programs with the GNU C++ compiler, `g++'.
  661.    For best results when debugging C++ programs, use the stabs debugging
  662. format.  You can select that format explicitly with the `g++'
  663. command-line options `-gstabs' or `-gstabs+'.  See *Note Options for
  664. Debugging Your Program or GNU CC: (gcc.info)Debugging Options, for more
  665. information.
  666. * Menu:
  667. * C Operators::                 C and C++ operators
  668. * C Constants::                 C and C++ constants
  669. * Cplus expressions::           C++ expressions
  670. * C Defaults::                  Default settings for C and C++
  671. * C Checks::                    C and C++ type and range checks
  672. * Debugging C::                 GDB and C
  673. * Debugging C plus plus::       Special features for C++
  674. File: gdb.info,  Node: C Operators,  Next: C Constants,  Up: C
  675. C and C++ operators
  676. -------------------
  677.    Operators must be defined on values of specific types.  For instance,
  678. `+' is defined on numbers, but not on structures.  Operators are often
  679. defined on groups of types.
  680.    For the purposes of C and C++, the following definitions hold:
  681.    * *Integral types* include `int' with any of its storage-class
  682.      specifiers; `char'; and `enum'.
  683.    * *Floating-point types* include `float' and `double'.
  684.    * *Pointer types* include all types defined as `(TYPE *)'.
  685.    * *Scalar types* include all of the above.
  686. The following operators are supported.  They are listed here in order
  687. of increasing precedence:
  688.      The comma or sequencing operator.  Expressions in a
  689.      comma-separated list are evaluated from left to right, with the
  690.      result of the entire expression being the last expression
  691.      evaluated.
  692.      Assignment.  The value of an assignment expression is the value
  693.      assigned.  Defined on scalar types.
  694. `OP='
  695.      Used in an expression of the form `A OP= B', and translated to
  696.      `A = A OP B'.  `OP=' and `=' have the same precendence.  OP is any
  697.      one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
  698.      `/', `%'.
  699.      The ternary operator.  `A ? B : C' can be thought of as:  if A
  700.      then B else C.  A should be of an integral type.
  701.      Logical OR.  Defined on integral types.
  702.      Logical AND.  Defined on integral types.
  703.      Bitwise OR.  Defined on integral types.
  704.      Bitwise exclusive-OR.  Defined on integral types.
  705.      Bitwise AND.  Defined on integral types.
  706. `==, !='
  707.      Equality and inequality.  Defined on scalar types.  The value of
  708.      these expressions is 0 for false and non-zero for true.
  709. `<, >, <=, >='
  710.      Less than, greater than, less than or equal, greater than or equal.
  711.      Defined on scalar types.  The value of these expressions is 0 for
  712.      false and non-zero for true.
  713. `<<, >>'
  714.      left shift, and right shift.  Defined on integral types.
  715.      The GDB "artificial array" operator (*note Expressions:
  716.      Expressions.).
  717. `+, -'
  718.      Addition and subtraction.  Defined on integral types,
  719.      floating-point types and pointer types.
  720. `*, /, %'
  721.      Multiplication, division, and modulus.  Multiplication and
  722.      division are defined on integral and floating-point types.
  723.      Modulus is defined on integral types.
  724. `++, --'
  725.      Increment and decrement.  When appearing before a variable, the
  726.      operation is performed before the variable is used in an
  727.      expression; when appearing after it, the variable's value is used
  728.      before the operation takes place.
  729.      Pointer dereferencing.  Defined on pointer types.  Same precedence
  730.      as `++'.
  731.      Address operator.  Defined on variables.  Same precedence as `++'.
  732.      For debugging C++, GDB implements a use of `&' beyond what is
  733.      allowed in the C++ language itself: you can use `&(&REF)' (or, if
  734.      you prefer, simply `&&REF') to examine the address where a C++
  735.      reference variable (declared with `&REF') is stored.
  736.      Negative.  Defined on integral and floating-point types.  Same
  737.      precedence as `++'.
  738.      Logical negation.  Defined on integral types.  Same precedence as
  739.      `++'.
  740.      Bitwise complement operator.  Defined on integral types.  Same
  741.      precedence as `++'.
  742. `., ->'
  743.      Structure member, and pointer-to-structure member.  For
  744.      convenience, GDB regards the two as equivalent, choosing whether
  745.      to dereference a pointer based on the stored type information.
  746.      Defined on `struct' and `union' data.
  747.      Array indexing.  `A[I]' is defined as `*(A+I)'.  Same precedence
  748.      as `->'.
  749.      Function parameter list.  Same precedence as `->'.
  750.      C++ scope resolution operator.  Defined on `struct', `union', and
  751.      `class' types.
  752.      Doubled colons also represent the GDB scope operator (*note
  753.      Expressions: Expressions.).  Same precedence as `::', above.
  754. File: gdb.info,  Node: C Constants,  Next: Cplus expressions,  Prev: C Operators,  Up: C
  755. C and C++ constants
  756. -------------------
  757.    GDB allows you to express the constants of C and C++ in the
  758. following ways:
  759.    * Integer constants are a sequence of digits.  Octal constants are
  760.      specified by a leading `0' (ie. zero), and hexadecimal constants by
  761.      a leading `0x' or `0X'.  Constants may also end with a letter `l',
  762.      specifying that the constant should be treated as a `long' value.
  763.    * Floating point constants are a sequence of digits, followed by a
  764.      decimal point, followed by a sequence of digits, and optionally
  765.      followed by an exponent.  An exponent is of the form:
  766.      `e[[+]|-]NNN', where NNN is another sequence of digits.  The `+'
  767.      is optional for positive exponents.
  768.    * Enumerated constants consist of enumerated identifiers, or their
  769.      integral equivalents.
  770.    * Character constants are a single character surrounded by single
  771.      quotes (`''), or a number--the ordinal value of the corresponding
  772.      character (usually its ASCII value).  Within quotes, the single
  773.      character may be represented by a letter or by "escape sequences",
  774.      which are of the form `\NNN', where NNN is the octal representation
  775.      of the character's ordinal value; or of the form `\X', where `X'
  776.      is a predefined special character--for example, `\n' for newline.
  777.    * String constants are a sequence of character constants surrounded
  778.      by double quotes (`"').
  779.    * Pointer constants are an integral value.  You can also write
  780.      pointers to constants using the C operator `&'.
  781.    * Array constants are comma-separated lists surrounded by braces `{'
  782.      and `}'; for example, `{1,2,3}' is a three-element array of
  783.      integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and
  784.      `{&"hi", &"there", &"fred"}' is a three-element array of pointers.
  785. File: gdb.info,  Node: Cplus expressions,  Next: C Defaults,  Prev: C Constants,  Up: C
  786. C++ expressions
  787. ---------------
  788.    GDB expression handling has a number of extensions to interpret a
  789. significant subset of C++ expressions.
  790.      *Warning:* GDB can only debug C++ code if you compile with the GNU
  791.      C++ compiler.  Moreover, C++ debugging depends on the use of
  792.      additional debugging information in the symbol table, and thus
  793.      requires special support.  GDB has this support *only* with the
  794.      stabs debug format.  In particular, if your compiler generates
  795.      a.out, MIPS ECOFF, RS/6000 XCOFF, or ELF with stabs extensions to
  796.      the symbol table, these facilities are all available.  (With GNU
  797.      CC, you can use the `-gstabs' option to request stabs debugging
  798.      extensions explicitly.)  Where the object code format is standard
  799.      COFF or DWARF in ELF, on the other hand, most of the C++ support
  800.      in GDB does *not* work.
  801.   1. Member function calls are allowed; you can use expressions like
  802.           count = aml->GetOriginal(x, y)
  803.   2. While a member function is active (in the selected stack frame),
  804.      your expressions have the same namespace available as the member
  805.      function; that is, GDB allows implicit references to the class
  806.      instance pointer `this' following the same rules as C++.
  807.   3. You can call overloaded functions; GDB resolves the function call
  808.      to the right definition, with one restriction--you must use
  809.      arguments of the type required by the function that you want to
  810.      call.  GDB does not perform conversions requiring constructors or
  811.      user-defined type operators.
  812.   4. GDB understands variables declared as C++ references; you can use
  813.      them in expressions just as you do in C++ source--they are
  814.      automatically dereferenced.
  815.      In the parameter list shown when GDB displays a frame, the values
  816.      of reference variables are not displayed (unlike other variables);
  817.      this avoids clutter, since references are often used for large
  818.      structures.  The *address* of a reference variable is always
  819.      shown, unless you have specified `set print address off'.
  820.   5. GDB supports the C++ name resolution operator `::'--your
  821.      expressions can use it just as expressions in your program do.
  822.      Since one scope may be defined in another, you can use `::'
  823.      repeatedly if necessary, for example in an expression like
  824.      `SCOPE1::SCOPE2::NAME'.  GDB also allows resolving name scope by
  825.      reference to source files, in both C and C++ debugging (*note
  826.      Program variables: Variables.).
  827. File: gdb.info,  Node: C Defaults,  Next: C Checks,  Prev: Cplus expressions,  Up: C
  828. C and C++ defaults
  829. ------------------
  830.    If you allow GDB to set type and range checking automatically, they
  831. both default to `off' whenever the working language changes to C or
  832. C++.  This happens regardless of whether you, or GDB, selected the
  833. working language.
  834.    If you allow GDB to set the language automatically, it sets the
  835. working language to C or C++ on entering code compiled from a source
  836. file whose name ends with `.c', `.C', or `.cc'.  *Note Having GDB infer
  837. the source language: Automatically, for further details.
  838. File: gdb.info,  Node: C Checks,  Next: Debugging C,  Prev: C Defaults,  Up: C
  839. C and C++ type and range checks
  840. -------------------------------
  841.    By default, when GDB parses C or C++ expressions, type checking is
  842. not used.  However, if you turn type checking on, GDB considers two
  843. variables type equivalent if:
  844.    * The two variables are structured and have the same structure,
  845.      union, or enumerated tag.
  846.    * Two two variables have the same type name, or types that have been
  847.      declared equivalent through `typedef'.
  848.    Range checking, if turned on, is done on mathematical operations.
  849. Array indices are not checked, since they are often used to index a
  850. pointer that is not itself an array.
  851. File: gdb.info,  Node: Debugging C,  Next: Debugging C plus plus,  Prev: C Checks,  Up: C
  852. GDB and C
  853. ---------
  854.    The `set print union' and `show print union' commands apply to the
  855. `union' type.  When set to `on', any `union' that is inside a `struct'
  856. or `class' is also printed.  Otherwise, it appears as `{...}'.
  857.    The `@' operator aids in the debugging of dynamic arrays, formed
  858. with pointers and a memory allocation function.  *Note Expressions:
  859. Expressions.
  860. File: gdb.info,  Node: Debugging C plus plus,  Prev: Debugging C,  Up: C
  861. GDB features for C++
  862. --------------------
  863.    Some GDB commands are particularly useful with C++, and some are
  864. designed specifically for use with C++.  Here is a summary:
  865. `breakpoint menus'
  866.      When you want a breakpoint in a function whose name is overloaded,
  867.      GDB breakpoint menus help you specify which function definition
  868.      you want.  *Note Breakpoint menus: Breakpoint Menus.
  869. `rbreak REGEX'
  870.      Setting breakpoints using regular expressions is helpful for
  871.      setting breakpoints on overloaded functions that are not members
  872.      of any special classes.  *Note Setting breakpoints: Set Breaks.
  873. `catch EXCEPTIONS'
  874. `info catch'
  875.      Debug C++ exception handling using these commands.  *Note
  876.      Breakpoints and exceptions: Exception Handling.
  877. `ptype TYPENAME'
  878.      Print inheritance relationships as well as other information for
  879.      type TYPENAME.  *Note Examining the Symbol Table: Symbols.
  880. `set print demangle'
  881. `show print demangle'
  882. `set print asm-demangle'
  883. `show print asm-demangle'
  884.      Control whether C++ symbols display in their source form, both when
  885.      displaying code as C++ source and when displaying disassemblies.
  886.      *Note Print settings: Print Settings.
  887. `set print object'
  888. `show print object'
  889.      Choose whether to print derived (actual) or declared types of
  890.      objects.  *Note Print settings: Print Settings.
  891. `set print vtbl'
  892. `show print vtbl'
  893.      Control the format for printing virtual function tables.  *Note
  894.      Print settings: Print Settings.
  895. `Overloaded symbol names'
  896.      You can specify a particular definition of an overloaded symbol,
  897.      using the same notation that is used to declare such symbols in
  898.      C++: type `SYMBOL(TYPES)' rather than just SYMBOL.  You can also
  899.      use the GDB command-line word completion facilities to list the
  900.      available choices, or to finish the type list for you.  *Note
  901.      Command completion: Completion, for details on how to do this.
  902. File: gdb.info,  Node: Modula-2,  Prev: C,  Up: Support
  903. Modula-2
  904. --------
  905.    The extensions made to GDB to support Modula-2 only support output
  906. from the GNU Modula-2 compiler (which is currently being developed).
  907. Other Modula-2 compilers are not currently supported, and attempting to
  908. debug executables produced by them is most likely to give an error as
  909. GDB reads in the executable's symbol table.
  910. * Menu:
  911. * M2 Operators::                Built-in operators
  912. * Built-In Func/Proc::           Built-in functions and procedures
  913. * M2 Constants::                Modula-2 constants
  914. * M2 Defaults::                 Default settings for Modula-2
  915. * Deviations::                  Deviations from standard Modula-2
  916. * M2 Checks::                   Modula-2 type and range checks
  917. * M2 Scope::                    The scope operators `::' and `.'
  918. * GDB/M2::                      GDB and Modula-2
  919. File: gdb.info,  Node: M2 Operators,  Next: Built-In Func/Proc,  Up: Modula-2
  920. Operators
  921. ---------
  922.    Operators must be defined on values of specific types.  For instance,
  923. `+' is defined on numbers, but not on structures.  Operators are often
  924. defined on groups of types.  For the purposes of Modula-2, the
  925. following definitions hold:
  926.    * *Integral types* consist of `INTEGER', `CARDINAL', and their
  927.      subranges.
  928.    * *Character types* consist of `CHAR' and its subranges.
  929.    * *Floating-point types* consist of `REAL'.
  930.    * *Pointer types* consist of anything declared as `POINTER TO TYPE'.
  931.    * *Scalar types* consist of all of the above.
  932.    * *Set types* consist of `SET' and `BITSET' types.
  933.    * *Boolean types* consist of `BOOLEAN'.
  934. The following operators are supported, and appear in order of
  935. increasing precedence:
  936.      Function argument or array index separator.
  937.      Assignment.  The value of VAR `:=' VALUE is VALUE.
  938. `<, >'
  939.      Less than, greater than on integral, floating-point, or enumerated
  940.      types.
  941. `<=, >='
  942.      Less than, greater than, less than or equal to, greater than or
  943.      equal to on integral, floating-point and enumerated types, or set
  944.      inclusion on set types.  Same precedence as `<'.
  945. `=, <>, #'
  946.      Equality and two ways of expressing inequality, valid on scalar
  947.      types.  Same precedence as `<'.  In GDB scripts, only `<>' is
  948.      available for inequality, since `#' conflicts with the script
  949.      comment character.
  950.      Set membership.  Defined on set types and the types of their
  951.      members.  Same precedence as `<'.
  952.      Boolean disjunction.  Defined on boolean types.
  953. `AND, &'
  954.      Boolean conjuction.  Defined on boolean types.
  955.      The GDB "artificial array" operator (*note Expressions:
  956.      Expressions.).
  957. `+, -'
  958.      Addition and subtraction on integral and floating-point types, or
  959.      union and difference on set types.
  960.      Multiplication on integral and floating-point types, or set
  961.      intersection on set types.
  962.      Division on floating-point types, or symmetric set difference on
  963.      set types.  Same precedence as `*'.
  964. `DIV, MOD'
  965.      Integer division and remainder.  Defined on integral types.  Same
  966.      precedence as `*'.
  967.      Negative. Defined on `INTEGER' and `REAL' data.
  968.      Pointer dereferencing.  Defined on pointer types.
  969. `NOT'
  970.      Boolean negation.  Defined on boolean types.  Same precedence as
  971.      `^'.
  972.      `RECORD' field selector.  Defined on `RECORD' data.  Same
  973.      precedence as `^'.
  974.      Array indexing.  Defined on `ARRAY' data.  Same precedence as `^'.
  975.      Procedure argument list.  Defined on `PROCEDURE' objects.  Same
  976.      precedence as `^'.
  977. `::, .'
  978.      GDB and Modula-2 scope operators.
  979.      *Warning:* Sets and their operations are not yet supported, so GDB
  980.      treats the use of the operator `IN', or the use of operators `+',
  981.      `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
  982.      error.
  983.